#include "Parser.h"
#include "Semantic.h"
#include <cstdlib>

// print the parser tree
void printTree(ParserTree* tree)
{
	if (tree)
	{
		if (!tree->isDOT())
		{
			if (tree->isNumber())
				std::cout << tree->getAtom().number;
			else
				std::cout << tree->getAtom().str.c_str();
		}
		else
		{
			std::cout << "( ";
			if (tree->getChild(true))
				printTree(tree->getChild(true));
			else
				std::cout << "NIL";
			std::cout << " . ";
			if (tree->getChild(false))
				printTree(tree->getChild(false));
			else
				std::cout << "NIL";
			std::cout << " )";
		}
	}
}


int main(int argc, char* argv[])
{
	Parser parser;
	Semantic semantic;

	parser.nextToken();

	while(!parser.isFileEnd())
	{
		ParserTree* tree = parser.parseList();
		//printTree(tree);			//	if you'd like to see the parse tree, uncommented thi line;
		semantic.printValue(tree, AList());
		std::cout << '\n';
		delete tree;
		parser.nextToken();

	}

	return 0;
}

